
import facade

from xjlibrary.our_file_dir import BaseDir

curPath = BaseDir.get_file_dir_absolute(__file__)
TopPath = BaseDir.get_upper_dir(curPath, -2)
sPath = BaseDir.get_new_path(TopPath, "download", "rucjournal", "download", "detail")
BaseDir.create_dir(sPath)
dbconfigpath = BaseDir.get_new_path(curPath, "db.ini")


class DownDetail(object):
    def __init__(self):
        self.logger = facade.get_streamlogger()
        self.mysqlutils = facade.MysqlUtiles(dbconfigpath, "db", logger=self.logger)
        self.proxy = {
            "http": "192.168.30.176:8207",
            "https": "192.168.30.176:8207"
        }
        self.headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
            "Cache-Control": "no-cache",
            "Host": "www.rdfybk.com",
            "Pragma": "no-cache",
            "Referer": "http://www.rdfybk.com/qw/detail?id=51883&kw=",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
        }

    def selectDb(self):
        sql = "select rawid from article"
        rows = self.mysqlutils.SelectFromDB(sql)
        with open(file="./id.txt", mode="a", encoding="utf-8") as f:
            for row in rows:
                value = row[0] + "\n"
                f.write(value)


if __name__ == "__main__":
    down = DownDetail()
    down.selectDb()
